<?php

namespace App\Admin\Actions\Grid\Customer;

use App\Admin\Forms\Customer\RemarkForm;
use Dcat\Admin\Grid\RowAction;
use Dcat\Admin\Widgets\Modal;

class Remark extends RowAction
{
    protected $title = '备注';
    protected bool $is_sale;

    public function __construct(bool $is_sale)
    {
        $this->is_sale = $is_sale;
        parent::__construct($this->title);
    }

    public function render(): string|Modal
    {
        // 实例化表单类并传递自定义参数
        $form = RemarkForm::make()->payload([
            'id' => $this->getKey(),
            'remark' => $this->is_sale ? $this->row->sale_remark : $this->row->return_remark,
            'is_sale' => $this->is_sale
        ]);

        return Modal::make()
            ->lg()
            ->title($this->title)
            ->body($form)
            ->button('<a href="javascript:void(0)"><i class="feather icon-edit"> ' . $this->title . '</i></a>');
    }
}
